package com.fh.user.controller;/**
 * 描述:
 * Author:袁亚强
 * Date:2021/12/98:53
 */

import com.fh.common.baseData.TongyiData;
import com.fh.common.exceptions.ParamException;
import com.fh.user.entity.vo.User;
import com.fh.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * created by macro on 2021/12/9,
 */
@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;

    //1 发送验证码到邮箱中     1  发送成功   0 邮箱已注册过    2已经发送过了
    @PostMapping("sendemail")
    public TongyiData sendEmail(String email) {
        if (StringUtils.isEmpty(email)) {
            throw new ParamException();
        }
        return TongyiData.succeess(userService.sendMimeMail(email));
    }

    //2 验证验证码            1  验证成功   0 验证马不正确  2验证码已过期
    @PostMapping("validatecode")
    @ResponseBody
    public TongyiData validatecode(String email, String code) {
        if (StringUtils.isEmpty(email)) {
            throw new ParamException();
        }
        return TongyiData.succeess(userService.validatecode(email, code));
    }


    @PostMapping("addUser")   //  1  注册成功   0 账号已经存在
    public TongyiData addUser(User user) {
        return TongyiData.succeess(userService.addUser(user));
    }

    @PostMapping("login")
    public TongyiData login(String name, String password) {
        return TongyiData.succeess(userService.login(name, password));
    }


    @PostMapping("queryToken")
    public TongyiData queryToken(String token) {
        return TongyiData.succeess(userService.queryToken(token));
    }
}
